package com.zryc.shop.sms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.pms.entity.Product;
import com.zryc.shop.sms.entity.FlashPromotion;
import com.zryc.shop.sms.mapper.FlashPromotionMapper;
import com.zryc.shop.sms.service.IFlashPromotionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 限时购表 服务实现类
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@Service
public class FlashPromotionServiceImpl extends ServiceImpl<FlashPromotionMapper, FlashPromotion> implements IFlashPromotionService {

    @Override
    public Page<FlashPromotion> list(String keyword, Integer pageNum, Integer pageSize) {
        Page<FlashPromotion> page = new Page<>(pageNum, pageSize);
        QueryWrapper<FlashPromotion> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(keyword)) {
            wrapper.like("title", keyword);
        }
        return page(page, wrapper);
    }

    @Override
    public Object updateStatus(Long id, Integer status) {
        UpdateWrapper<FlashPromotion> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("status", status);
        update(updateWrapper);
        return null;
    }

    /**
     * 更新秒杀活动
     *
     * @param id
     * @param flashPromotion
     * @return
     */
    @Override
    public Object updateFlash(Long id, FlashPromotion flashPromotion) {
        UpdateWrapper<FlashPromotion> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        baseMapper.update(flashPromotion,updateWrapper);
        return null;
    }
}
